package trading.util;

import java.io.IOException;
import java.util.HashSet;
import java.util.Properties;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

/**
 * allow retrieving the properties set by the configurer.
 * 
 * @author mjacob
 */
public class QueryablePropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer implements InitializingBean {
    private final Properties _properies = new Properties();

    @Override
    public void afterPropertiesSet() throws IOException {
        Properties rawProps = new Properties();
        super.loadProperties(rawProps);

        for (String key : rawProps.stringPropertyNames()) {
            String originalValue = (String)rawProps.get(key);

            String evaluatedProperty = super.parseStringValue(originalValue, rawProps, new HashSet<String>());
            _properies.setProperty(key, evaluatedProperty);
        }
    }

    public Properties getProperties() {
        return _properies;
    }
}
